package dao.impl;

import com.google.common.collect.ImmutableMap;
import dao.WorkExperienceDao;
import domain.WorkExperience;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by aceyin on 15/7/2.
 */
@Repository
public class WorkExperienceDaoImpl extends BaseGenericDao<WorkExperience, Long> implements WorkExperienceDao {
    @Override
    public List<Long> findUserHasExperience(List<Long> userIds, String category) {
        Map<String, Object> params = ImmutableMap.<String, Object>builder()
                .put("category", category)
                .put("ids", userIds)
                .build();
        return queryList("find-user-has-experience", params);
    }

    @Override
    public void increaseExperience(List<Long> userHasExperience, String typeCode) {
        Map<String, Object> params = ImmutableMap.<String, Object>builder()
                .put("category", typeCode)
                .put("list", userHasExperience)
                .build();
        update("increase-work-experience", params);
    }

    @Override
    public void addExperience(List<Long> appliers, String typeCode) {
        List<WorkExperience> experiences = new ArrayList<>();
        for (Long l : appliers) {
            WorkExperience w = new WorkExperience();
            w.setAccountId(l);
            w.setCategory(typeCode);
            w.setTimes(1);
            experiences.add(w);
        }
        batchInsert(experiences);
    }

    @Override
    public List<WorkExperience> findExperiences(long id) {
        Map<String, Object> params = ImmutableMap.<String, Object>builder().put("id", id).build();
        return queryList("find-experiences-by-user-id", params);
    }
}
